package com.sgb.zhaocai.view.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.databinding.ActivityPickAddInvitedWebsiteBinding;
import com.sgb.zhaocai.entity.AddInviteExternalListBean;
import com.swgk.core.base.AppActivity;
import com.swgk.core.base.di.Activity;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.MToast;

import java.io.Serializable;
import java.util.List;

/**
 * Time:2021/12/20
 * AUTHOR:F_Q
 * Description:邀请非网站客户-新增界面
 */
public class PickAddInvitedWebSiteActivity  extends AppActivity {

    private ActivityPickAddInvitedWebsiteBinding mBinding;


    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_pick_add_invited_website);
        mBinding.includeTitle.titleView.setText("新增");
        mBinding.includeTitle.ivBack.setOnClickListener(v -> finish());
        mBinding.phone.setInfilterType(ItemInputTextView.TYPE_NUM);
        AddInviteExternalListBean.AddInviteDataBean dataBean = (AddInviteExternalListBean.AddInviteDataBean) getIntent().getSerializableExtra("data");
        if (dataBean!=null){
            mBinding.companyName.setContent(dataBean.getCompanyName());
            mBinding.contact.setContent(dataBean.getContacts());
            mBinding.phone.setContent(dataBean.getTelephone());
        }
        mBinding.save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveData();
            }
        });
    }

    private void saveData() {
        if (TextUtils.isEmpty(mBinding.contact.getContent())){
            MToast.showToast(this,"请输入联系人");
            return;
        }
        if (TextUtils.isEmpty(mBinding.phone.getContent())){
            MToast.showToast(this,"请输入手机号");
            return;
        }
        if (!CheckUtils.isMobile(mBinding.phone.getContent().trim())) {
            MToast.showToast(this, "请输入正确的手机号码");
            return;
        }
        AddInviteExternalListBean.AddInviteDataBean bean = new AddInviteExternalListBean.AddInviteDataBean();
        bean.setCompanyName(mBinding.companyName.getContent()+"");
        bean.setContacts(mBinding.contact.getContent()+"");
        bean.setTelephone(mBinding.phone.getContent()+"");
        Intent intent = new Intent();
        intent.putExtra("data", (Serializable) bean);
        setResult(RESULT_OK, intent);
        finish();
    }
}
